home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / append DITL.c < prev    next >
Encoding:
Text File  |  1992-09-14  |  4.6 KB  |  139 lines  |  [TEXT/R*ch]

  1. short
  2. AppendDITL( DialogPtr the_dialog, short the_DITL_ID );
  3.  
  4. /* This code is translated from the Pascal in Tech Note 95. */
  5. short
  6. AppendDITL( DialogPtr the_dialog, short the_DITL_ID )
  7. /* 
  8.     This routine appends all of the items of a specified DITL onto the
  9.     end of a specified DLOG --- we don't even need to know the format of
  10.     the DLOG.
  11. */
  12. {
  13.     typedef struct {
  14.         Handle    itmHndl; /* handle or procedure pointer for this item */
  15.         Rect    itmRect; /* display rectangle for this item */
  16.         char    itmType;    /* item type for this item - 1-byte number */
  17.         unsigned char    itmData[];  /* length byte, data */
  18.     } DITL_item, *pDITL_item, **hDITL_item;
  19.     
  20.     typedef struct {
  21.         short            dlg_max_index;    /* number of items minus 1 */
  22.         DITL_item    DITL_items[];    /* array of DITL_items */
  23.     } item_list, *p_item_list, **h_item_list;
  24.     
  25.     typedef short *IntPtr;
  26.     
  27.     Point    offset;    /* Used to offset rectangles of items being appended. */
  28.     Rect    maxRect; /* Used to track increase in window size. */
  29.     h_item_list    hDITL;  /* Handle to DITL being appended. */
  30.     pDITL_item    pItem;    /* Pointer to current item being appended. */
  31.     h_item_list    hItems;    /* Handle to DLOG's item list. */
  32.     short            firstItem;    /* Number of where first item is to be appended */
  33.     short            newItems;    /* Count of new items */
  34.     short            dataSize;    /* Size of data for current item */
  35.     short            i, j;            /* Working index */
  36.     short            USB;
  37.     OSErr        err;
  38.     char        *cp1, *cp2; /* working character pointers */
  39.     
  40. /* 
  41.     We use 3 steps:
  42.     1. append the items of the specified DITL onto the existing DLOG
  43.     2. expand the original dialog window as required
  44.     3. return the adjusted number of the first new user item
  45. */
  46. /* 
  47.     Using the original DLOG
  48.     
  49.     1. Remember the original window size
  50.     2. Set the offset Point to be the bottom of the original window
  51.     3. Subtract 5 pixels from the bottom and right, to be added
  52.        back later after we have possibly expanded window.
  53.     4. Get working Handle to original item list
  54.     5. Calculate our first item number to be returned to caller
  55.     6. Get locked Handle to DITL to be appended
  56.     7. Calculate count of new items.
  57. */
  58.  
  59.     maxRect = the_dialog->portRect;
  60.     offset.v = maxRect.bottom;
  61.     offset.h = 0;
  62.     maxRect.bottom -= 5;
  63.     maxRect.right -= 5;
  64.     hItems = (h_item_list) ((DialogPeek)the_dialog)->items;
  65.     firstItem = (**hItems).dlg_max_index + 2;
  66.     hDITL = (h_item_list) GetResource('DITL', the_DITL_ID );
  67.     HLock( (Handle)hDITL );
  68.     newItems = (**hDITL).dlg_max_index + 1;
  69. /* 
  70.     For each item,
  71.         1. Offset the rectangle to follow the original window.
  72.         2. Make the original window larger if necessary.
  73.         3. Fill in item Handle according to type.
  74. */
  75.     pItem = &(**hDITL).DITL_items[0];
  76.     for (i = 1; i <= newItems; i++)
  77.     {
  78.         OffsetRect( &pItem->itmRect, offset.h, offset.v );
  79.         UnionRect( &pItem->itmRect, &maxRect, &maxRect );
  80.         
  81.         USB = (unsigned char) pItem->itmData[0];
  82.         /* USB = USB << 8; */
  83.         
  84.         switch ( pItem->itmType & 0x7F )
  85.         {
  86.             case userItem:    /* Can't do anything meaningful with user items. */
  87.                 pItem->itmHndl = NIL;
  88.                 break;
  89.             case ctrlItem + btnCtrl:
  90.             case ctrlItem + chkCtrl:
  91.             case ctrlItem + radCtrl:
  92.                 pItem->itmHndl = (Handle) NewControl( the_dialog, 
  93.                     &pItem->itmRect,
  94.                     &pItem->itmData[0],    /* title */
  95.                     1, /* visible */
  96.                     0, 0, 1, /* value, min, max */
  97.                     (pItem->itmType & 0x03),    /* procID */
  98.                     0 ); /*  refcon */
  99.                     break;
  100.             case ctrlItem + resCtrl:
  101.                 pItem->itmHndl = (Handle) GetNewControl(
  102.                     *((short *) &pItem->itmData[1]),    /* control ID */
  103.                     the_dialog );
  104.                 (**( (ControlHandle) pItem->itmHndl )).contrlRect =
  105.                     pItem->itmRect;    /* give it the right rectangle */
  106.                 /* an actionproc for a control should be installed here */
  107.                 break;
  108.             case statText:
  109.             case editText: /* Both need Handle to a copy of their text */
  110.                 err = PtrToHand( &pItem->itmData[1], /* Start of data */
  111.                     &pItem->itmHndl,    /* Address of new Handle */
  112.                     (long)USB );    /* length of text */
  113.                 break;
  114.             case iconItem:    /* icon needs resource Handle */
  115.                 pItem->itmHndl = GetIcon( *((short *) &pItem->itmData[1]) );
  116.                 break;
  117.             case picItem:
  118.                 pItem->itmHndl = (Handle) GetPicture(
  119.                     *((short *) &pItem->itmData[1]) );
  120.                 break;
  121.             default:
  122.                 pItem->itmHndl = NIL;
  123.                 break;
  124.         } /* end of switch */
  125.         dataSize = (USB + 1) & 0xFFFE; /* round up to even number */
  126.         /* now advance to next item */
  127.         pItem = (pDITL_item) ((char *)pItem + dataSize + sizeof(DITL_item));
  128.     } /* endfor */
  129.     err = PtrAndHand( &(**hDITL).DITL_items,
  130.         (Handle)hItems,
  131.         GetHandleSize( (Handle)hDITL) );
  132.     (**hItems).dlg_max_index += newItems;
  133.     HUnlock( (Handle)hDITL );
  134.     ReleaseResource( (Handle)hDITL );
  135.     maxRect.bottom += 5;
  136.     maxRect.right += 5;
  137.     SizeWindow( the_dialog, maxRect.right, maxRect.bottom, 1 );
  138.     return( firstItem );
  139. }